package com.yz.design.responsibilityDegin;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * :延时订单处理Handler
 */
@Slf4j
public class DelayRemoveOrderHandler extends AbstractMessageHandler<Object, Message> {

    private static Lock lock = new ReentrantLock(true);

    @Override
    public Object handleMessage(Message message) {    //消费延时订单tag
        if (message.getTopic().equals(getTopic())) {
            log.info(" 监听订单删除消息,[topic:" + message.getTopic() + "], [tag:" + message.getTag() + "]。开始解析...");      //userId + UNDER_BAR + borrowOrderId
            try {
                String content = message.getBody();
                log.info("消费内容 userId_borrowOrderId :{}", content);
                //删除延时订单
                return new Object();
            } catch (Exception e) {        //消费失败，挂起当前队列
                log.error("延时订单:{}消费异常", message.getBody());
                return new Object();
            } finally {
                lock.unlock();
            }

        } else {
            if (nextHandler == null) {
                log.info("未匹配到topic:{}, tag:{}跳过,", message.getTopic(), message.getTag());
                return new Object();
            }
            return nextHandler.handleMessage(message);
        }
    }
}